#region Copyright 2006 - Evolution Tecnologia Ltda.
//
// Author: Rafael Franco Carvalho (rafael@Evolutiontec.com.br)
//
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: Groups.cs
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using csharp.common;

namespace csharp.rad.security
{
    public class Users
    {
        private List<User> usersItems = new List<User>();

        public List<User> Items
        {
            get
            {
                return usersItems;
            }
            set
            {
                usersItems = value;
            }
        }

        public Users()
        {

        }

        /// <summary>
        /// Get all security.users from specified group
        /// </summary>
        /// <param name="value">The GroupId</param>
        /// <remarks>value = null, get all security.users</remarks>
        /// <returns></returns>
        public void GetData(String value)
        {
            String commandText;
            //String tableName = "security.users";
            System.Data.DataSet sqlDataSet = new System.Data.DataSet();

            usersItems.Clear();
            //note: value = 0, get all security.users
            if (value == null)
            {
                //Get all security.users
                commandText = "SELECT user_name "
                            + "FROM security.users "
                            + "ORDER BY user_name";
            }
            else
            {
                //Get security.users of group
                commandText = "SELECT user_name "
                            + "FROM security.users "
                            + "WHERE (user_group_id = '" + value + "') "
                            + "ORDER BY user_name";
            }
            sqlDataSet = Database.ExecuteQuery(commandText);
            foreach (System.Data.DataRow dataRecord in sqlDataSet.Tables[0].Rows)
            {
                User userItem = new User();
                userItem.GetData(System.Convert.ToString(dataRecord["user_name"]));
                usersItems.Add(userItem);
            }
            sqlDataSet.Dispose();
        }

        public void Clear()
        {
            usersItems.Clear();
        }
    }
}
